#include <pthread.h>
#include <rid.h>
#include <stdint.h>
#include <stdio.h>

#include <fn85.h>
#include <rid_fn85.h>

#define NIT_SHORT_NAMES
#include <nit/list.h>
#include <nit/set.h>
#include <nit/map.h>

#include "../oas.h"

int
act(Rid self, const Rid sender, void *msg, void *local, Oas_sys *sys)
{
	Rid_fn85 str;

	if (!msg)
		return 1;

	rid_fn85(str, msg);
	printf("Hello, %s\n", str);
	return 0;
}

int
act2(Rid self, const Rid sender, void *msg, void *local, Oas_sys *sys)
{
	Rid_fn85 str;

	if (!msg)
		return 1;

	rid_fn85(str, msg);
	printf("Hello to %s\n", str);
	oas_msg(sys, self, msg, self);
	return 0;
}

int
act3(Rid self, const Rid sender, void *msg, void *local, Oas_sys *sys)
{
	Rid_fn85 str;

	rid_fn85(str, self);
	printf("Hello via %s\n", str);
	return 0;
}

void
die(Rid self, Oas_mail *mail, void *local, Oas_sys *sys)
{
	return;
}

int
main(int argc, char *argv[])
{
	Oas_sys sys;
	Rid id;
	Rid id2;
	Rid self;

	rid_set(id, NULL);
	rid_set(id2, NULL);
	rid_set(self, NULL);

	oas_init(&sys, NULL, NULL);
	oas_add(&sys, id, NULL, NULL, NULL, act, die);
	oas_add(&sys, id2, NULL, NULL, NULL, act2, die);
	oas_msg(&sys, self, id2, id);
	oas_wait(&sys);
	oas_dispose(&sys);
	return 0;
}
